Move ethkey crypto utils to parity crypto crate#210
Conversation
This comment has been minimized.
This comment has been minimized.
ordian
left a comment
There was a problem hiding this comment.
I haven't looked deeply at the code as it seems to be copied, but have some concerns about dependencies.
dvdplm
left a comment
There was a problem hiding this comment.
One thing I'm not clear about is if the code added here is entierly ethereum-specific or if there is stuff that is useful to other projects as well. You mentioned secret-store might be extracted after this. Are there other Parity projects that use/could use the crypto here?
/cc @cheme
| } | ||
|
|
||
| /// Inplace add one secret key to another (scalar + scalar) | ||
| pub fn add(&mut self, other: &Secret) -> Result<(), Error> { |
There was a problem hiding this comment.
There seems to be a lot of similar mathy methods here as well as in math.rs: maybe there's a trait here waiting to be discovered and impl'd for Secret and Public? add, sub, mul, neg, is_valid etc?
There was a problem hiding this comment.
But it's different algebraic groups (scalar and elliptic curve). I'm afraid, that general trait for them could lead to mistreatments
There was a problem hiding this comment.
Mistreatments, can you elaborate on that? How could it be abused?
IMHO @cheme was too ambitious in his PR :-) I want to achieve simpler objectives (move common code from ethkey and don't break anything dependent on parity-crypto). And we need to have it done, if we want to develop secret store further as a separate project. So I hope to bring it to the (happy) end. |
The primary beneficiary of this PR is secret store indeed. I'm not aware of other projects for sure. At the same time, we wanted to extract account management, removing this dependency from it could help. |
|
@dvdplm thanks for comments! It will be good to cleanup this code, as it was not touched for a while. |
|
@grbIzl I really appreciate the effort and the goal here! FWIW I tried something similar a while back and failed. |
Substrate uses |
|
I put newly added dependencies under the build feature (publickey). The only not implemented major thing is including of ethereum_types crate. H256 is used heavily in Signature and Secret classes and I would need to copypaste its functionality there. So for now I leave it as a dependency (but put under the same feature) |
ordian
left a comment
There was a problem hiding this comment.
Looks good in general, some minor suggestions.
cheme
left a comment
There was a problem hiding this comment.
With things moved inside a feature gated module, I guess we can have ethereum-type dependency and some former code moved with less hesitation.
|
|
||
| [features] | ||
| default = [] | ||
| publickey = ["eth-secp256k1", "lazy_static", "ethereum-types"] No newline at end of file |
There was a problem hiding this comment.
I am not sure about the rational of naming the feature 'publickey' , a comment could be good.
There was a problem hiding this comment.
Does it make sense to name this feature secp256k1? publickey seems too general
There was a problem hiding this comment.
I agree in general, but this exact name (secp256k1) seems not the best option, because we already have eth-secp256k1 feature and it will be two similar names. Naming is the hardest part of coding :-(
dvdplm
left a comment
There was a problem hiding this comment.
Good stuff here. I got ~half way through. Mostly nits and (I believe) mostly on old code that was copied over.
|
I think it's unfortunate that git history has not been preserved for these files as they migrated from the |
It's a common problem for such case, when files are moved to the other repo. So I've put a comment, but not sure, how helpful it will be |
| let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); | ||
| let mut public = generation_point(); | ||
| public_mul_secret(&mut public, &secret).unwrap(); | ||
| assert_eq!(format!("{:x}", public), "8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4"); |
There was a problem hiding this comment.
If this value is from a spec somewhere it'd be great to document that. :)
There was a problem hiding this comment.
It's just a randomly created secret
| name = "bench" | ||
| harness = false | ||
|
|
||
| required-features = ["publickey"] |
It is. The trick is to using something like |
| [package] | ||
| name = "parity-crypto" | ||
| version = "0.4.1" | ||
| version = "0.4.2" |
There was a problem hiding this comment.
Just a thought: while it's technically correct that the changes here are not breaking the previous API, I wonder if it's not warranted to go with 0.5 here anyway, just to signal the presence of a major new piece of functionality?
/cc @ordian
There was a problem hiding this comment.
I see where you're coming from and don't have a strong opinion on this. Having a minor release makes it easier to ensure other crates could use the latest version of parity-crypto (even via transitive dependencies), but that's a minor concern.
| } | ||
|
|
||
| /// Compute power of secret key inplace (secret ^ pow). | ||
| /// This function is not intended to be used with large powers. |
There was a problem hiding this comment.
Why not? And what is the limit? And what happens if one does? Panic? Panic or overflowing behaviour should be documented.
There was a problem hiding this comment.
I've removed this comment as it's misleading. The only limitation here is pow (usize). The multiplication on elliptic curves doesn't have any limitations
dvdplm
left a comment
There was a problem hiding this comment.
🎉
So what are the next steps after this? A PR to parity-ethereum to use this I guess?
Yep. |
|
k, I'm putting this |
|
|
||
| [dependencies] | ||
| tiny-keccak = "1.4" | ||
| eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "a96ad75", optional = true } |
There was a problem hiding this comment.
| eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "a96ad75", optional = true } | |
| eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "72c93ab = true } |
another update
|
@grbIzl @dvdplm let's publish a new version of |
Working on it. Right now bumped into paritytech/rust-secp256k1#25 |
The intention of this PR is to remove dependency to accounts\ethkey for parity components, that use crypto utils from it. That would allow further decomposition of parity repo. Including move of secret store into the separate repo.
Additional comments: